using AutoMapper;
using Common.Communal;
using MediatR;
using Scheduling.Api.Write.Application.Command.ScheduleCommand;
using Scheduling.Services.Schedules;
using ERP.Domain.Scheduling;

namespace Scheduling.Api.Write.Application.CommandHandlers.ScheduleHandler
{
    public class ScheduleAddCommandHandler : IRequestHandler<ScheduleAddCommand, ApiResult<int>>
    {
        public ScheduleAddCommandHandler(IScheduleServices scheduleServices, IMapper mapper)
        {
            ScheduleServices = scheduleServices;
            Mapper = mapper;
        }

        public IScheduleServices ScheduleServices { get; }
        public IMapper Mapper { get; }

        public async Task<ApiResult<int>> Handle(ScheduleAddCommand request, CancellationToken cancellationToken)
        {
            var model = Mapper.Map<Schedule>(request);
            return await ScheduleServices.AddSchedule(model);
        }
    }
}
